from sort_A_simply_sort import simply_sort

n, k = map(int, input().split())
work_time = list(map(int, input().split()))
stack, count = 0, 0

simply_sort(work_time)

for i, num in enumerate(work_time):
    if num < n:
        if stack + num < n:
            stack += num
            count = i + 1
    else:
        break

print(count)
